package com.pangus.toolkits.files.util;

import com.pangus.toolkits.files.result.R;
import com.squareup.okhttp.mockwebserver.MockResponse;
import okhttp3.*;

/**
 * @author yingheng chen
 * @description
 * @date 2019/12/4
 */

public class MockUtil {
    public final static Request anyRequest = new Request.Builder().url("https://some-url.com").build();

    public static Response mock(Request mockRequest, String jsonContent) {
        return new Response.Builder()
                .request(mockRequest)
                .protocol(Protocol.HTTP_1_1)
                .code(200) // status code
                .message("ok")
                .body(ResponseBody.create(
                        MediaType.get("application/json; charset=utf-8"),
                        jsonContent
                ))
                .build();
    }

    public static MockResponse jsonResponse(String jsonContent) {
        return new MockResponse()
                .addHeader("Content-Type", "application/json; charset=utf-8")
                .setBody(jsonContent);

    }

    public static MockResponse jsonResponse(R res) {
        return new MockResponse()
                .addHeader("Content-Type", "application/json; charset=utf-8")
                .setBody(res.toString());

    }
}
